<%@ page contentType="text/html; charset=UTF-8" language="java" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@ include file="include.jsp" %>
<%@ include file="menu.jsp" %>
<style type="text/css">
    .title {
        text-align: center;
        font-family: sans-serif;
        font-size: larger;
        color: #6699cc;
        width: 1000px;
        margin: 0 auto;
    }

    .grid {
        width: 1000px;
        margin: 0 auto;

    }

    .grid table {
        width: 100%;
       // border-collapse: collapse;
        font-size: 12px;
        font-family: Verdana;

    }

    .table_head {
        font-size: medium;
        text-align: center;
        font-weight: bold;
        background-color: #6699cc;
    }

    tr {
        height: 25px;
    }

    .form {
        width: 1000px;
        margin: 0 auto;
        font-family: sans-serif;
        font-style: normal;

    }

    .form select {
        width: 300px;
        border: medium solid #FFFFFF;
        background-color: #e0e0e0;
    }

    .form input {
        width: 300px;
    }

    input.button {
        cursor: pointer;
        background-color: #FFCC00;
        font-weight: bold;
        width: 100px;

    }

    .form td {
        font-size: x-small;
        font-weight: bold;

    }

    .required {
        color: red;
    }

    .active {
        background-color: #E1FFA7;
    }

    .inactive {
        background-color: #FFDDDC;
    }

    .table_row_1 {
        background-color: #e0e0e0;
    }
</style>
<div class="title">Управление пользователями</div>
<br>

<div class="grid">
    <table>
        <tr class="table_head">
            <td>Имя</td>
            <td>Фамилия</td>
            <td>Логин</td>
            <td>Почта</td>
            <td>Статус</td>
            <td>Роль</td>
            <td></td>
            <td></td>
        </tr>
        <c:set var="count" value="0" scope="page"/>
        <c:forEach items="${users}" var="u">
            <c:set var="count" value="${count + 1}" scope="page"/>
            <tr <c:if test="${(count % 2) == 0}"><c:out value="class=table_row_1"/></c:if> >
                <td><c:out value="${u.firstName}"/></td>
                <td><c:out value="${u.lastName}"/></td>
                <td><c:out value="${u.login}"/></td>
                <td><c:out value="${u.email}"/></td>
                <td align="center"
                        
                        <c:set var="statusName" value="${u.status.statusName}"/>
                        <c:if test="${statusName eq 'active'}"><c:out value="class=active"/></c:if>
                        <c:if test="${statusName eq 'inactive'}"><c:out value="class=inactive"/></c:if>

                        ><c:out value="${u.status.alias}"/></td>
                <td align="center"><c:out value="${u.role.alias}"/></td>
                <c:url var="editUrl" value="/admin/createUser.htm">
                    <c:param name="action" value="edit"/>
                    <c:param name="userId" value="${u.userId}"/>
                </c:url>

                <td align="center"><a href="${editUrl}"><img style="border:0px;" src="../images/edit.png"
                                                             alt="Edit"></a></td>

                <c:url var="deleteUrl" value="/admin/deleteUser.htm">
                    <c:param name="action" value="delete"/>
                    <c:param name="userId" value="${u.userId}"/>
                </c:url>

                <td align="center"><a href="${deleteUrl}"><img style="border:0px;" src="../images/delete_red.png"
                                                               alt="Delete"></a></td>
            </tr>
        </c:forEach>
    </table>

</div>

<br>

<form:form method="POST" commandName="newUser" cssClass="form">
    <table style="width:800px">

        <tr>
            <td>Имя<span class="required">*</span></td>
            <td><form:input path="firstName"/></td>
            <td><form:errors path="firstName" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td>Фамилия<span class="required">*</span></td>
            <td><form:input path="lastName"/></td>
            <td><form:errors path="lastName" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td>Логин<span class="required">*</span></td>
            <td><form:input path="login"/></td>
            <td><form:errors path="login" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td>Электропочта<span class="required">*</span></td>
            <td><form:input path="email"/></td>
            <td><form:errors path="email" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td>Пароль<span class="required">*</span></td>
            <td><form:password path="password"/></td>
            <td><form:errors path="password" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td>Пароль еще раз<span class="required">*</span></td>
            <td><form:password path="password"/></td>
            <td><form:errors path="password" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td>Роль<span class="required">*</span></td>
            <td>
                <form:select path="role">
                    <form:options items="${allRoles}" itemValue="roleId" itemLabel="alias"/>
                </form:select>
            </td>
            <td><form:errors path="role" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td>Статус<span class="required">*</span></td>
            <td>
                Активна : <form:radiobutton path="status" value="active"/><br>
                Неактивна : <form:radiobutton path="status" value="inactive"/>
            </td>
            <td><form:errors path="status" cssStyle="color:red;"/></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td><input type="submit" value="submit" name="_finish" class="button"></td>
        </tr>
    </table>
</form:form>
